/***************************************************************************
 * The Open Armory API is a project to retrieve World of Warcraft(R) 
 * related XML data from The Armory.
 * 
 * The data retrieved via the Open Armory API from The Armory is 
 * proprietary to Blizzard Entertainment, Inc(R).
 * *************************************************************************
 * Copyright (C) 2009 - 2010 Tedla M.B. Brandsema
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************************/
package net.openarmory.core.domain;

import java.io.File;
import java.io.InputStream;

import net.openarmory.core.domain.constants.ArmoryZone;

/**
 * The Class {@code ArmoryItemXmlWriter} writes the XML data retrieved via the
 * {@link ArmoryItemXmlRetriever} to disk.
 */
public final class ArmoryItemXmlWriter extends ArmoryXmlWriter {

	/** The item XML retriever. */
	private final ArmoryItemXmlRetriever itemXmlRetriever = new ArmoryItemXmlRetriever();

	/**
	 * Writes a character specific item tooltip to disk.
	 * 
	 * @param zone
	 *            The zone represents The Armory region (i.e. EU or US).
	 * @param itemId
	 *            The id number of the item.
	 * @param realm
	 *            The realm on which the character resides on.
	 * @param characterName
	 *            The character name.
	 * @param slot
	 *            The item slot where the item is equipped represented by an
	 *            integer value (i.e. head = 0, etc...).
	 */
	public void writeCharacterSpecificItemTooltipXml(final ArmoryZone zone,
			final int itemId, final String realm, final String characterName,
			final int slot) {
		final InputStream characterSpecificItemTooltipInputStream = this.itemXmlRetriever
				.fetchCharacterSpecificItemTooltipXml(zone, itemId, realm,
						characterName, slot);
		final String outFilename = Integer.toString(itemId) + ".xml";
		final File outFile = createOutFile(outFilename, zone, realm,
				characterName, true);
		writeXmlFile(characterSpecificItemTooltipInputStream, outFile);
	}

	/**
	 * Writes an item tooltip to disk.
	 * 
	 * @param zone
	 *            The zone represents The Armory region (i.e. EU or US).
	 * @param itemId
	 *            The id number of the item.
	 */
	public void writeItemTooltipXml(final ArmoryZone zone, final int itemId) {
		final InputStream itemTooltipInputStream = this.itemXmlRetriever
				.fetchItemTooltipXml(zone, itemId);
		final String outFilename = Integer.toString(itemId) + ".xml";
		final File outFile = createOutFile(outFilename, null, null, null, false);
		writeXmlFile(itemTooltipInputStream, outFile);
	}
}
